﻿using System;
using DDDNorthWind.AC.ImportProducts.Domain.ValueObjects;
using DDDNorthWind.AC.Products.Domain.Entities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TechTalk.SpecFlow;

namespace DDDNorthWind.Test.Acceptance
{
    
    [Binding]
    public class ImportProductSteps
    {
        private Product product;
        private readonly ImportProductSize sizes=new ImportProductSize();

        private bool esEstadoOk;

        #region Given
        [Given(@"I have one product imported")]
        public void GivenHaveOneProductImported()
        {
            product = new Product();
        }

        [Given(@"entered high (\d+) into product sizes")]
        public void GivenEnteredHighHighIntoProductSizes(int numberToEnter)
        {
            sizes.High = numberToEnter;
        }

        [Given(@"entered width (.*) into product sizes")]
        public void GivenEnteredWidthIntoProductSizes(string numberToEnter)
        {
            sizes.Width = int.Parse(numberToEnter);

        }

        [Given(@"entered long (\d+) into product sizes")]
        public void GivenEnteredLong(int numberToEnter)
        {
            sizes.Length = numberToEnter;
        }

        [Given(@"entered dimensions in (.*) into product sizes")]
        public void GivenEnteredDimensionIn(string dimensionIn)
        {
            sizes.DimensionIn = string.IsNullOrWhiteSpace(dimensionIn)
                                 ? ImportDimension.CM
                                 : (ImportDimension)Enum.Parse(typeof(ImportDimension), dimensionIn);

        }

        [Given(@"entered weight (.*) into product sizes")]
        public void GivenEnteredWeight(string newValue)
        {
            var weight = double.Parse(newValue);

            product.AssignImportWeight(weight);
            //ScenarioContext.Current.Pending();
            //sizes.Weight = int.Parse(newValue);
        }

        [Given(@"entered Unit Of Weight in (.*) into product sizes")]
        public void GivenEnteredWeightIn(string weightIn)
        {
            //ScenarioContext.Current.Pending();
            //sizes.WeightIn = string.IsNullOrWhiteSpace(weightIn)
            //                     ? ImportUnitOfWeight.GR
            //                     : (ImportUnitOfWeight)Enum.Parse(typeof(ImportUnitOfWeight), weightIn);
        }

        [Given(@"a file with correct format to import")]
        public void GivenAFileWithCorrectFormatToImport()
        {
            ScenarioContext.Current.Pending();
        }

        [Given(@"a file with incorrect format to import")]
        public void GivenAFileWithIncorrectFormatToImport()
        {
            ScenarioContext.Current.Pending();
        }
        #endregion

        #region When
        [When(@"I assign the product category")]
        public void WhenIAssignTheProductCategory()
        {
            ScenarioContext.Current.Pending();
        }

        [When(@"I assign the product size")]
        public void WhenIAssignTheProductSize()
        {
            ScenarioContext.Current.Pending();
        }

        [When(@"I assign product sizes to product")]
        public void WhenIAssignProductSizes()
        {
            
            //sut.AssignedSizes += (sender, e) => { esEstadoOk = true; };

            
            ScenarioContext.Current.Pending();
            //sut.AssignImportSizes(sizes);

        }

        [When(@"I create the product")]
        public void WhenICreateTheProduct()
        {
            ScenarioContext.Current.Pending();
        }

        [When(@"I read the file")]
        public void WhenIReadTheFile()
        {
            ScenarioContext.Current.Pending();
        } 
        #endregion

        #region Then
        [Then(@"the state should be (.*) state")]
        public void TheStateShouldBe(string stateExpected)
        {
            if (stateExpected.Equals("canBuy"))
                Assert.IsTrue(esEstadoOk);
            else if (stateExpected.Equals("pending"))
                Assert.IsFalse(esEstadoOk);
        }

        [Then(@"the product is ready to buy")]
        public void ThenTheProductIsReadyToBuy()
        {
            ScenarioContext.Current.Pending();
        }

        [Then(@"the product not is in product to assign category")]
        public void ThenTheProductNotIsInProductToAssignCategory()
        {
            ScenarioContext.Current.Pending();
        }

        [Then(@"the user is presented with an error message")]
        public void ThenTheUserIsPresentedWithAnErrorMessage()
        {
            ScenarioContext.Current.Pending();
        }

        [Then(@"the product not is in product to assign sizes")]
        public void ThenTheProductNotIsInProductToAssignSizes()
        {
            ScenarioContext.Current.Pending();
        }

        [Then(@"the catalog contain the new products")]
        public void ThenTheCatalogContainTheNewProducts()
        {
            ScenarioContext.Current.Pending();
        } 
        #endregion


        //How to expected exception
        //try
        //{
        //    calculator.Add(1,1);
        //}
        //catch (Exception e)
        //{
        //    ScenarioContext.Current.Add("Exception_CalculatorAdd", e);
        //}

        //In your Then you could check the thrown exception and to asserts on it;

        //var exception = ScenarioContext.Current["Exception_CalculatorAdd"];
        //Assert.That(exception, Is.Not.Null);

    }
}
